TypeVars in public classes should be public
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 6
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
Current status:
- Imports of public classes are using the technique described in https://github.com/ni/nitypes-python/issues/16#issuecomment-3090219859 .
- Imports of TypeVars and TypeAliases are not.
classmethod from_array_1d(array: numpy.typing.NDArray[_TOtherRaw], dtype: None = ..., *, copy: bool = ..., start_index: SupportsIndex | None = ..., sample_count: SupportsIndex | None = ..., extended_properties: collections.abc.Mapping[str, nitypes.waveform.ExtendedPropertyValue] | None = ..., timing: nitypes.waveform.Timing[nitypes.waveform._timing._AnyDateTime, nitypes.waveform._timing._AnyTimeDelta, nitypes.waveform._timing._AnyTimeDelta] | None = ..., scale_mode: nitypes.waveform.ScaleMode | None = ...)→ AnalogWaveform[_TOtherRaw]
nitypes.waveform.ExtendedPropertyValue, nitypes.waveform.Timing, and nitypes.waveform.ScaleMode are the public exports.
nitypes.waveform._timing._AnyDateTime and nitypes.waveform._timing._AnyTimeDelta are TypeAliases in a private submodule.
_TOtherRaw is a TypeVar in a private submodule. Sphinx-autoapi is not displaying its submodule name here, but I think there may be some situations where it does.
After discussion with @mshafer-NI, I think it makes sense to do the following:
- Make TypeAliases (e.g.
_AnyTimeDelta) public or replace them with the corresponding unions (e.g.bt.TimeDelta | dt.timedelta | ht.timedelta)- Make TypeVars (e.g.
_TOtherRaw) public
- Challenge: some of the waveforms use the same TypeVar name with different bounds. These may need to live in separate submodules or be renamed.
In a few years, Python 3.11 will go EOL. At that point, we can replace the TypeVars with PEP 695 generic syntax. However, we do not necessarily need to break compatibility with code that imports our exported TypeVars. We can keep exporting them as long as we want, and we can also implement a module-level
__getattr__that emits DeprecationWarning if they are imported.
Originally posted by @bkeryan in #16
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the nitypes.waveform API and the documented AnalogWaveform.from_array_1d example, then inspect the private _timing TypeAliases and _TOtherRaw TypeVar referenced in the issue. Compare the public exports with the generated documentation and determine how differing TypeVar bounds should be handled. Done means public annotations no longer expose unintended private TypeVars or aliases while the proposed compatibility behavior is accounted for.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100