You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is incredibly useful for any situation where you need a delta, or a partially-constructed / curried form of an object. For example, when processing a PATCH request in an HTTP framework, a Partial object lets you avoid re-defining a class or working with unstructured JSON because you already know all the attributes you might receive and now you can just test them for None-ness. Or in a test framework where 90% of the attributes are initialized with the same defaults, you can provide a function that takes a partial type which populates only the attributes which are unspecified.
The absence of object literals makes this slightly less useful in Python, but maybe if we added **kw to object.__init__ to assign as attributes, it would be even better :).
The text was updated successfully, but these errors were encountered:
I'm closing this, as it's a feature request for the typing system in general, rather than a feature request for mypy specifically. Proposals like this should go to the https://github.com/python/typing repo or the typing-sig mailing list.
Feature
In TypeScript you can say
Partial<X>
and get an object whose attributes are allOptional
; I would like this in some form for Mypy.See https://www.typescriptlang.org/docs/handbook/utility-types.html
Pitch
This is incredibly useful for any situation where you need a delta, or a partially-constructed / curried form of an object. For example, when processing a
PATCH
request in an HTTP framework, aPartial
object lets you avoid re-defining a class or working with unstructured JSON because you already know all the attributes you might receive and now you can just test them forNone
-ness. Or in a test framework where 90% of the attributes are initialized with the same defaults, you can provide a function that takes a partial type which populates only the attributes which are unspecified.The absence of object literals makes this slightly less useful in Python, but maybe if we added
**kw
toobject.__init__
to assign as attributes, it would be even better :).The text was updated successfully, but these errors were encountered: