1- class OSMObject (object ):
1+ from typing import Optional , Union , Any , Mapping , Sequence , Tuple , TYPE_CHECKING
2+ from datetime import datetime
3+
4+ if TYPE_CHECKING :
5+ import osmium .osm
6+
7+ OSMObjectLike = Union ['OSMObject' , osmium .osm .OSMObject ]
8+ NodeLike = Union [Node , osmium .osm .Node ]
9+ WayLike = Union [Way , osmium .osm .Way ]
10+ RelationLike = Union [Relation , osmium .osm .Relation ]
11+
12+ TagSequence = Union [osmium .osm .TagList , Mapping [str , str ], Sequence [Tuple [str , str ]]]
13+ LocationLike = Union [osmium .osm .Location , Tuple [float , float ]]
14+ NodeSequence = Union [osmium .osm .NodeRefList , Sequence [Union [osmium .osm .NodeRef , int ]]]
15+ MemberSequence = Union [osmium .osm .RelationMemberList ,
16+ Sequence [Union [osmium .osm .RelationMember , Tuple [str , int , str ]]]]
17+
18+ class OSMObject :
219 """Mutable version of ``osmium.osm.OSMObject``. It exposes the following
320 attributes ``id``, ``version``, ``visible``, ``changeset``, ``timestamp``,
421 ``uid`` and ``tags``. Timestamps may be strings or datetime objects.
@@ -9,8 +26,11 @@ class OSMObject(object):
926 will be initialised first from the attributes of this base object.
1027 """
1128
12- def __init__ (self , base = None , id = None , version = None , visible = None , changeset = None ,
13- timestamp = None , uid = None , tags = None , user = None ):
29+ def __init__ (self , base : Optional ['OSMObjectLike' ] = None ,
30+ id : Optional [int ] = None , version : Optional [int ] = None ,
31+ visible : Optional [bool ] = None , changeset : Optional [int ] = None ,
32+ timestamp : Optional [datetime ] = None , uid : Optional [int ] = None ,
33+ tags : Optional ['TagSequence' ] = None , user : Optional [str ] = None ) -> None :
1434 if base is None :
1535 self .id = id
1636 self .version = version
@@ -37,7 +57,9 @@ class Node(OSMObject):
3757 may either be an `osmium.osm.Location` or a tuple of lon/lat coordinates.
3858 """
3959
40- def __init__ (self , base = None , location = None , ** attrs ):
60+ def __init__ (self , base : Optional ['NodeLike' ] = None ,
61+ location : Optional ['LocationLike' ] = None ,
62+ ** attrs : Any ) -> None :
4163 OSMObject .__init__ (self , base = base , ** attrs )
4264 if base is None :
4365 self .location = location
@@ -52,7 +74,8 @@ class Way(OSMObject):
5274 ``osmium.osm.NodeRef`` or simple node ids.
5375 """
5476
55- def __init__ (self , base = None , nodes = None , ** attrs ):
77+ def __init__ (self , base : Optional ['WayLike' ] = None ,
78+ nodes : Optional ['NodeSequence' ] = None , ** attrs : Any ) -> None :
5679 OSMObject .__init__ (self , base = base , ** attrs )
5780 if base is None :
5881 self .nodes = nodes
@@ -67,9 +90,33 @@ class Relation(OSMObject):
6790 member type should be a single character 'n', 'w' or 'r'.
6891 """
6992
70- def __init__ (self , base = None , members = None , ** attrs ):
93+ def __init__ (self , base : Optional ['RelationLike' ] = None ,
94+ members : Optional ['MemberSequence' ] = None , ** attrs : Any ) -> None :
7195 OSMObject .__init__ (self , base = base , ** attrs )
7296 if base is None :
7397 self .members = members
7498 else :
7599 self .members = members if members is not None else base .members
100+
101+
102+ def create_mutable_node (node : 'NodeLike' , ** args : Any ) -> Node :
103+ """ Create a mutable node replacing the properties given in the
104+ named parameters. Note that this function only creates a shallow
105+ copy which is still bound to the scope of the original object.
106+ """
107+ return Node (base = node , ** args )
108+
109+ def create_mutable_way (way : 'WayLike' , ** args : Any ) -> Way :
110+ """ Create a mutable way replacing the properties given in the
111+ named parameters. Note that this function only creates a shallow
112+ copy which is still bound to the scope of the original object.
113+ """
114+ return Way (base = way , ** args )
115+
116+ def create_mutable_relation (rel : 'RelationLike' , ** args : Any ) -> Relation :
117+ """ Create a mutable relation replacing the properties given in the
118+ named parameters. Note that this function only creates a shallow
119+ copy which is still bound to the scope of the original object.
120+ """
121+ return Relation (base = rel , ** args )
122+
0 commit comments