-
-
Notifications
You must be signed in to change notification settings - Fork 310
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
Use generic types for config objects. #1325
base: main
Are you sure you want to change the base?
Conversation
This is made to be consistent with typeshed best practices: > avoid invariant collection types (list, dict) in argument positions, in favor of covariant types like Mapping or Sequence Signed-off-by: Matt Gilson <[email protected]>
bb39c56
to
9e38577
Compare
If anyone would write such a thing
they could as easily write
Hardly a usecase we should be concerned about. :) |
I think that the bigger question is whether we want to prevent someone from using immutable objects in the Config objects (and whether there is a strong reason that we have to have a
Yes, I mostly agree. IMHO, the primary reason to make this change is to provide more flexibility for an end user. I certainly agree that if someone wants to do something degenerate here, they can and if they are determined, there's probably no good way to stop them. Having said that, I still think that (in the general case) using immutable type annotations can help users to avoid accidental bugs in circumstances like these. def non_pure_function(x: MutableSequence[Any]) -> int:
random.shuffle(x)
return 7
n = non_pure_function(MySchema.Config.unique)
... I sort of doubt that there is a use-case for doing something like this on these 1if it doesn't, we should use |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #1325 +/- ##
=======================================
Coverage 76.48% 76.48%
=======================================
Files 91 91
Lines 6676 6676
=======================================
Hits 5106 5106
Misses 1570 1570
☔ View full report in Codecov by Sentry. |
thanks for the contribution @mgilson, please see the contributing guide to see how to run pre-commit and local tests |
This is made to be consistent with typeshed best practices:
Specifically, we have a linter in house that complains about mutable defaults on class members:
I can't see any reason that
unique
must be alist
rather than atuple
(why would we ever need to mutate this object?). I haven't looked hard enough to determine if I think that there is a "danger" if someone goes andMySchema.Config.unique.append("c")
or accidentally mutates this via some oddball path of references at some other place in the code.