Open andylamp opened 2 years ago
I haven't done any work to make Rom specifically mypy compliant in any way.
I'll have to look at how other libraries do this, and how mypy recommends solving this when I get back to a computer in January.
On Sun, Feb 13, 2022, 9:34 AM andylamp @.***> wrote:
Hello,
Thanks for the awesome library! I would like to ask how can we allow custom classes derived from Column to pass mypy type checking?
for example, let us suppose we have the following (simple?) class:
class TransformedString(rom.Column): """ Transformation on strings """
_allowed = bytes def _to_redis(self, value): return value def _from_redis(self, value): return value
and suppose that we have the following ORM model:
class MyModel(rom.Model): """Entry representing a GitHub issue"""
id = rom.PrimaryKey(index=True) number = rom.Integer() html = TransformedString()
Now if I go and assign values as follows, while it works mypy throws an error.
assume an instance of
MyModel
my_model.number = 1 # works!my_model.html = str.encode("a_nice_long_string_with_many_features") # mypy throws an errorThe error mypy throws is the following:
error: Incompatible types in assignment (expression has type "bytes", variable has type "TransformedString")
How am I able to fix this without resorting to ignoring the types altogether?
— Reply to this email directly, view it on GitHub https://github.com/josiahcarlson/rom/issues/155, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABTDQQMA3PZFWKYPQUPHK3U27FRPANCNFSM5OJF33GA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you are subscribed to this thread.Message ID: @.***>
Hello,
Thanks for the awesome library! I would like to ask how can we allow custom classes derived from
Column
to passmypy
type checking. More concretely, let us suppose we have the following (simple?) class:and suppose that we have the following ORM model:
Now if I go and assign values as follows, while it works
mypy
throws an error.The error
mypy
throws is the following:How am I able to fix this without resorting to ignoring the types altogether?