-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python: refactor type.Type.* -> type.*? #888
Comments
n.b. coordinate with RLO https://github.com/awf/knossos/blob/8b53d51d3a738f131ba289b9fc782370664b421a/src/rlo/sparser.py if we do make this change |
Here's the best "community expectations" I could find: https://softwareengineering.stackexchange.com/questions/171296/staticmethod-vs-module-level-function |
Another datapont, pylint as configured https://github.com/awf/knossos/pull/1627#issuecomment-868670330 objects to to the
|
I quite like the namespacing of "Type.Float". Also, I like that before #882, every "Type.Float" returned the same instance, whereas IIUC, after #882, each read of Type.Float returns a new instance. (Can we combine @classproperty with @cachedproperty ??) But, trying to construct a simple example, akin to the situation before #882: class Foo:
def __init__(self, s):
self.s = s
def __str__(self):
return f"Foo<{self.s}>"
Foo.ex = Foo("ex")
print(Foo.ex) running this prints "Foo" as expected. mypy complains, as expected:
However, the following patch makes mypy happy:
is that another option, or do other people dislike the namespacing of the old approach (i.e. #882 is not just about mypy) ? |
Yes, the change will have caused there to be more allocation for e.g. That looks like another reasonable alternative. As a variation of that, that's more typed (when in Type do as the Typers do...): class Type
# ...
Float: "Type"
# ...
# After
Type.Float = Type("Float") Is much closer to the original code and achieves much of the same - mypy / pylance pass, tests pass. Keeps performance of the "primitives" e.g. |
I'm very happy to do this latest version, sorts out types, passes pylint but also happy with the larger change of module functions if folks prefer that. |
I admit to a slight cosmetic preference for |
I think I prefer either type.Type.* -> type.* or the last one proposed by Alan. Classproperty seems too complicated for the goal (make mypy happy) |
Drop classproperty, just "declare" attributes in advance (#909) alternative from @acl33 #888 (comment)
We've merged @acl33 suggestion as a simpler option than |
Closed by #909 ? |
Thanks @cgravill ! from ksc.type import Integer, Float would mean from ksc import type probably not so good, as that shadows the builtin function |
Post #882, all type constructors are static methods on class
Type
in moduletype
.Clients then
We could lift them to module level to make the API
What are the pros and cons of such a change?
The text was updated successfully, but these errors were encountered: