comparison hgext/phabricator.py @ 49863:92743e6d1a0c

typing: disable a bogus attribute-error warning in phabricator In a local pytype run, this fixes: File "/mnt/c/Users/Matt/hg/hgext/phabricator.py", line 359, in <lambda>: No attribute 'items' on bytes [attribute-error] In Union[Any, bytes] Called from (traceback): line 363, in process The `bytes` case takes the previous `if` branch though.
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 05 Jan 2023 19:53:02 -0500
parents de9ffb82ef4d
children 18c8c18993f0
comparison
equal deleted inserted replaced
49862:b1147450c55c 49863:92743e6d1a0c
351 flattened to {'a[0]': 'b', 'a[1]': 'c', 'd[e]': 'f'} and then passed to 351 flattened to {'a[0]': 'b', 'a[1]': 'c', 'd[e]': 'f'} and then passed to
352 urlencode. Note: the encoding is consistent with PHP's http_build_query. 352 urlencode. Note: the encoding is consistent with PHP's http_build_query.
353 """ 353 """
354 flatparams = util.sortdict() 354 flatparams = util.sortdict()
355 355
356 def process(prefix, obj): 356 def process(prefix: bytes, obj):
357 if isinstance(obj, bool): 357 if isinstance(obj, bool):
358 obj = {True: b'true', False: b'false'}[obj] # Python -> PHP form 358 obj = {True: b'true', False: b'false'}[obj] # Python -> PHP form
359 lister = lambda l: [(b'%d' % k, v) for k, v in enumerate(l)] 359 lister = lambda l: [(b'%d' % k, v) for k, v in enumerate(l)]
360 # .items() will only be called for a dict type
361 # pytype: disable=attribute-error
360 items = {list: lister, dict: lambda x: x.items()}.get(type(obj)) 362 items = {list: lister, dict: lambda x: x.items()}.get(type(obj))
363 # pytype: enable=attribute-error
361 if items is None: 364 if items is None:
362 flatparams[prefix] = obj 365 flatparams[prefix] = obj
363 else: 366 else:
364 for k, v in items(obj): 367 for k, v in items(obj):
365 if prefix: 368 if prefix: