-
Notifications
You must be signed in to change notification settings - Fork 5
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
Cannot use self in method params #8
Comments
Oh, also, if I have two classes in the same file which accept instances of each other, I can't list them in the |
Crap, sorry. Didn't mean to close the issue. |
Hey @RobertPeters, currently we don't have a good support for that. The workaround is, as in the In this case it's not a good solution though, since Python doesn't double-check the type (like it does for the Currently I have two ideas on how to solve this, but I don't particularly like any of them, they both feel kind of clunky: The first idea is to allow specifying the type using strings:
I don't like this because it's not clear how scoping would work (ie. where to look for the 'Thing' at the moment of type checking), and because it's easy to make a typo that won't show up until the method is executed. The second idea is to allow functions in type signatures (as described in #5):
This has the drawback that it's much uglier, esp. when you've got several of them in
Any feedback on which would work better for your case (or if there's another, better way), please chime in. |
I lean towards the first option because it's cleaner, but I understand what you say about scoping. I'm not too worried about typos because generally you aren't going to find out you have a type error until you run the code anyway. Would it be possible to make strings valid only for the class they occur in? For example |
Regarding your question about strings being valid only for enclosing class - yes, (or we could have a special I took the easy (to code and reason about), but not entirely correct, way out: every type has a name attribute. If string is used instead of a type, we just check that the provided string matches the type name (whatever it is and wherever it came from). This means we don't have to worry about scoping This means that if you have classes The implementation is in #9 but I'd like to get some feedback on whether this makes sense before I merge it. Thoughts? |
I'm no coding genius, but I would be perfectly happy with your suggested solution. I can't think there's too many cases where you would be using types in a new type with the same name. It would be confusing as hell. Would your solution also mean we would right |
Yes, that would work as well. |
Fixed in 0.0.4 which I've just published on PyPI. |
Thanks for being so responsive, senko. I'll update and crack on. |
Hi. Sorry to bother you again. I have the following situation:
The
thing=Thing
gives me an "Unresolved reference error". Is there syntax for this already and I'm just missing it? Thanks.The text was updated successfully, but these errors were encountered: