[
https://issues.apache.org/jira/browse/BEAM-8490?focusedWorklogId=352444&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-352444
]
ASF GitHub Bot logged work on BEAM-8490:
----------------------------------------
Author: ASF GitHub Bot
Created on: 03/Dec/19 05:13
Start Date: 03/Dec/19 05:13
Worklog Time Spent: 10m
Work Description: udim commented on pull request #9894: [BEAM-8490] Fix
instance_to_type for empty containers
URL: https://github.com/apache/beam/pull/9894#discussion_r352987526
##########
File path: sdks/python/apache_beam/typehints/trivial_inference.py
##########
@@ -65,18 +65,27 @@ def instance_to_type(o):
elif t == tuple:
return typehints.Tuple[[instance_to_type(item) for item in o]]
elif t == list:
- return typehints.List[
- typehints.Union[[instance_to_type(item) for item in o]]
- ]
+ if len(o):
+ return typehints.List[
+ typehints.Union[[instance_to_type(item) for item in o]]
+ ]
+ else:
+ return typehints.List[typehints.Any]
Review comment:
I think it's equivalent. It's defined here:
https://www.python.org/dev/peps/pep-0483/#summary-of-gradual-typing (look at
the 3 bullet points).
Tuple is an immutable list. Its type hint has 2 forms:
- Tuple[type1[, type2[, ..]]], i.e., you specify the type for every index
- Tuple[type, ...], i.e., a homogenous list (note that `...` parses in
Python as Ellipsis)
Could explain the contravariant vs invariant situation?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 352444)
Time Spent: 50m (was: 40m)
> Python typehints: properly resolve empty dict type
> --------------------------------------------------
>
> Key: BEAM-8490
> URL: https://issues.apache.org/jira/browse/BEAM-8490
> Project: Beam
> Issue Type: Bug
> Components: sdk-py-core
> Reporter: Udi Meiri
> Assignee: Udi Meiri
> Priority: Major
> Time Spent: 50m
> Remaining Estimate: 0h
>
> Currently:
> {code}
> trivial_inference.instance_to_type({})
> {code}
> returns
> {code}
> Dict[Union[], Union[]]
> {code}
> instead of
> {code}
> Dict[Any,Any]
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)