Skip to content

Commit 84a087b

Browse files
add type annotations to block.py (#2634)
* add type annotations to block.py --------- Co-authored-by: Isaac Muse <[email protected]>
1 parent 70e475c commit 84a087b

File tree

10 files changed

+118
-79
lines changed

10 files changed

+118
-79
lines changed

docs/src/markdown/extensions/blocks/api.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class MyBlock(Block):
162162
# Name used for the block
163163
NAME = 'my-block'
164164
OPTIONS = {
165-
'tag_name': ['default', type_html_indentifier]
165+
'tag_name': ('default', type_html_indentifier)
166166
}
167167
```
168168

@@ -340,7 +340,7 @@ you'd want to use.
340340

341341
```py
342342
class Block:
343-
OPTIONS = {'name': [{}, type_any]}
343+
OPTIONS = {'name': ({}, type_any)}
344344
```
345345

346346
### `type_none`
@@ -355,7 +355,7 @@ indicate the option is "unset". See [`type_multi`](#type_multi) to learn how to
355355

356356
```py
357357
class Block:
358-
OPTIONS = {'name': [none, type_multi(type_none, type_string)]}
358+
OPTIONS = {'name': (none, type_multi(type_none, type_string))}
359359
```
360360

361361
### `type_number`
@@ -371,7 +371,7 @@ Returns the valid number (`float` or `int`) or raises a `ValueError`.
371371

372372
```py
373373
class Block:
374-
OPTIONS = {'keyword': [0.0, type_number]}
374+
OPTIONS = {'keyword': (0.0, type_number)}
375375
```
376376

377377
### `type_integer`
@@ -387,7 +387,7 @@ Returns the valid `int` or raises a `ValueError`.
387387

388388
```py
389389
class Block:
390-
OPTIONS = {'keyword': [0, type_integer]}
390+
OPTIONS = {'keyword': (0, type_integer)}
391391
```
392392

393393
### `type_ranged_number`
@@ -404,7 +404,7 @@ Returns the valid number (`float` or `int`) or raises a `ValueError`.
404404

405405
```py
406406
class Block:
407-
OPTIONS = {'keyword': [0.0, type_ranged_number(0.0, 100.0)]}
407+
OPTIONS = {'keyword': (0.0, type_ranged_number(0.0, 100.0))}
408408
```
409409

410410
### `type_ranged_integer`
@@ -422,7 +422,7 @@ Returns the valid `int` or raises a `ValueError`.
422422

423423
```py
424424
class Block:
425-
OPTIONS = {'keyword': [0, type_ranged_integer(0, 100)]}
425+
OPTIONS = {'keyword': (0, type_ranged_integer(0, 100))}
426426
```
427427

428428
### `type_boolean`
@@ -438,7 +438,7 @@ Returns the valid boolean or raises a `ValueError`.
438438

439439
```py
440440
class Block:
441-
OPTIONS = {'keyword': [False, type_boolean]}
441+
OPTIONS = {'keyword': (False, type_boolean)}
442442
```
443443

444444
### `type_ternary`
@@ -454,7 +454,7 @@ Returns the valid `bool` or `#!py3 None` or raises a `ValueError`.
454454

455455
```py
456456
class Block:
457-
OPTIONS = {'keyword': [None, type_ternary]}
457+
OPTIONS = {'keyword': (None, type_ternary)}
458458
```
459459

460460
### `type_string`
@@ -470,7 +470,7 @@ Returns the valid `str` or raises a `ValueError`.
470470

471471
```py
472472
class Block:
473-
OPTIONS = {'keyword': ['default', type_string]}
473+
OPTIONS = {'keyword': ('default', type_string)}
474474
```
475475

476476
### `type_insensitive_string`
@@ -486,7 +486,7 @@ Returns the valid, lowercase `str` or raises a `ValueError`.
486486

487487
```py
488488
class Block:
489-
OPTIONS = {'keyword': ['default', type_insensitive_string]}
489+
OPTIONS = {'keyword': ('default', type_insensitive_string)}
490490
```
491491

492492
### `type_string_in`
@@ -504,7 +504,7 @@ Returns the valid `str` or raises a `ValueError`.
504504

505505
```py
506506
class Block:
507-
OPTIONS = {'keyword': ['this', type_string_in(['this', 'that'], type_insensitive_string)]}
507+
OPTIONS = {'keyword': ('this', type_string_in(['this', 'that'], type_insensitive_string))}
508508
```
509509

510510
### `type_string_delimiter`
@@ -521,7 +521,7 @@ Returns a list of valid `str` values or raises a `ValueError`.
521521

522522
```py
523523
class Block:
524-
OPTIONS = {'keyword': ['default', type_string_delimiter(',' type_insensitive_string)]}
524+
OPTIONS = {'keyword': ('default', type_string_delimiter(',' type_insensitive_string))}
525525
```
526526

527527
### `type_html_identifier`
@@ -538,7 +538,7 @@ Returns a `str` that is a valid identifier or raises `ValueError`.
538538

539539
```py
540540
class Block:
541-
OPTIONS = {'keyword': ['default', type_html_indentifier]}
541+
OPTIONS = {'keyword': ('default', type_html_indentifier)}
542542
```
543543

544544
### `type_html_classes`
@@ -555,7 +555,7 @@ Returns a list of `str` that are valid CSS classes or raises `ValueError`.
555555

556556
```py
557557
class Block:
558-
OPTIONS = {'keyword': ['default', type_html_classes]}
558+
OPTIONS = {'keyword': ('default', type_html_classes)}
559559
```
560560

561561
### `type_html_attribute_dict`
@@ -581,7 +581,7 @@ Returns a `dict[str, Any]` where the values will either be `str` or `list[str]`
581581

582582
```py
583583
class Block:
584-
OPTIONS = {'attributes': [{}, type_html_attribute_dict]}
584+
OPTIONS = {'attributes': ({}, type_html_attribute_dict)}
585585
```
586586

587587
## `type_multi`

pymdownx/blocks/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Generic blocks extension."""
2-
from markdown import Extension
2+
from markdown import Extension, Markdown
33
from markdown.blockprocessors import BlockProcessor
44
from markdown.treeprocessors import Treeprocessor
55
from markdown import util as mutil
@@ -150,7 +150,7 @@ def run(self, doc):
150150
class BlocksProcessor(BlockProcessor):
151151
"""Generic block processor."""
152152

153-
def __init__(self, parser, md):
153+
def __init__(self, parser, md: Markdown):
154154
"""Initialization."""
155155

156156
self.md = md
@@ -347,12 +347,12 @@ def get_parent(self, parent):
347347
temp = self.lastChild(temp)
348348
return None
349349

350-
def is_raw(self, tag):
350+
def is_raw(self, tag: etree.Element) -> bool:
351351
"""Is tag raw."""
352352

353353
return tag.tag in self.raw_tags
354354

355-
def is_block(self, tag):
355+
def is_block(self, tag: etree.Element) -> bool:
356356
"""Is tag block."""
357357

358358
return tag.tag in self.block_tags

pymdownx/blocks/admonition.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Admonition(Block):
2525
NAME = 'admonition'
2626
ARGUMENT = None
2727
OPTIONS = {
28-
'type': ['', type_html_identifier],
28+
'type': ('', type_html_identifier),
2929
}
3030
DEF_TITLE = None
3131
DEF_CLASS = None

0 commit comments

Comments
 (0)