Skip to content

Commit fd70a55

Browse files
committed
docs: changed __enter__ to open automatically
document the changes from pyserial#240
1 parent 8b0eaf2 commit fd70a55

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

documentation/pyserial_api.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -515,13 +515,18 @@ Native ports
515515
>>> with serial.serial_for_url(port) as s:
516516
... s.write(b'hello')
517517

518-
Here no port argument is given, so it is not opened automatically:
518+
The port is opened automatically:
519519

520-
>>> with serial.Serial() as s:
521-
... s.port = ...
522-
... s.open()
520+
>>> port = serial.Serial()
521+
>>> port.port = '...'
522+
>>> with port as s:
523523
... s.write(b'hello')
524524

525+
Which also means that ``with`` statements can be used repeatedly,
526+
each time opening and closing the port.
527+
528+
.. versionchanged:: 3.4 the port is automatically opened
529+
525530

526531
.. method:: __exit__(exc_type, exc_val, exc_tb)
527532

@@ -618,7 +623,7 @@ Native ports
618623

619624
.. method:: isOpen()
620625

621-
.. deprecated:: 3.0 see :attr:`is_open`
626+
.. deprecated:: 3.0 see :attr:`is_open`
622627

623628
.. attribute:: writeTimeout
624629

0 commit comments

Comments
 (0)